package com.adams.access.db.bean;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "T_ROLE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Role extends EntityObject
{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4872530213892609566L;

	private String roleName; // 角色名
	private String description; // 角色详细介绍
	
	
	private Set<ViewEvent> events = new HashSet<ViewEvent>();

	  //权限   最小元素=事件
	    @OneToMany(cascade = CascadeType.REFRESH,fetch = FetchType.EAGER)
	    @JoinTable(name = "T_ROLE_EVENT", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "event_id") })
	    public Set<ViewEvent> getEvents() {
	        return events;
	    }

	    public void setEvents(Set<ViewEvent> events) {
	        this.events = events;
	    }
	
	

	private Set<Right> rights = new HashSet<Right>();

	@OneToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "T_ROLE_RIGHT", joinColumns =
	{ @JoinColumn(name = "role_id") }, inverseJoinColumns =
	{ @JoinColumn(name = "right_id") })
	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	public Set<Right> getRights()
	{
		return rights;
	}

	public void setRights(Set<Right> rights)
	{
		this.rights = rights;
	}

	@Column(length = 64, nullable = false)
	public String getRoleName()
	{
		return roleName;
	}

	public void setRoleName(String roleName)
	{
		this.roleName = roleName;
	}

	@Column(length = 128)
	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

}
